class Solution {
public:
    string addBinary(string a, string b) {
        int reta=a.size()-1;
        int retb=b.size()-1;
        string tmp;
        int x=0;
        while(reta>=0||retb>=0||x>0)
        {
            if(reta>=0)
            {
                x+=a[reta--]-'0';
            }
            if(retb>=0)
            {
                x+=b[retb--]-'0';
            }
            tmp+=x%2+'0';
            x/=2;
        }
        reverse(tmp.begin(),tmp.end());
        return tmp;
    }
};
